<template>
  <div>
    <div class="returnTitle">
      <el-page-header @back="goBack" content="添加学校量表"></el-page-header>
    </div>
    <div class="center">
      <el-form ref="form" :model="form" label-width="100px" label-position="right">
        <el-form-item label="选择量表：">
          <el-button type="primary" @click="addMeasurementFn" size="mini">选择量表</el-button>
          <br>
          <el-tag v-if="this.title !== ''" closable @close="handleClose()">{{this.title}}</el-tag>
        </el-form-item>
        <el-form-item label="测评类型：">
          <el-select v-model="form.type" placeholder="请选择全部测评类型" size="small">
            <el-option v-for="item in selection" :key="item.id" :label="item.title" :value="item.id"> </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="测评题量：">
          <el-input v-model="form.topics_num" show-word-limit>
            <template slot="append">题</template>
          </el-input>
        </el-form-item>
        <el-form-item label="做答时间：">
          <el-input v-model="form.time_spent" show-word-limit>
            <template slot="append">分钟</template>
          </el-input>
        </el-form-item>
        <el-form-item label="量表状态：">
          <el-radio v-model="form.is_show" label="1">显示</el-radio>
          <el-radio v-model="form.is_show" label="0">隐藏</el-radio>
        </el-form-item>
        <el-form-item class="inputBox">
          <el-button type="primary" @click="submitFn()">保 存</el-button>
        </el-form-item>
      </el-form>
    </div>
    <add-measurement v-if="isAddMeasurement" :isAddMeasurement="this.isAddMeasurement" @noAddMeasurement="noAddMeasurement"></add-measurement>
  </div>
</template>
<script>
import {APIGAUGEGETEVALUATIONTYPELIST, APIGAUGEADDSCALEINFO} from '@/common/api.js'
import addMeasurement from './addMeasurement.vue'
export default {
  components: {
    addMeasurement
  },
  data () {
    return {
      title: '',
      form: {
        is_show: '',
        topics_num: '',
        time_spent: '',
        type: '',
        platform_type: 1, // 1--是学生2--家长
        surveyls_survey_id: ''
      },
      selection: [],
      isAddMeasurement: false
    }
  },
  created () {
    this.selectionFn()
  },
  methods: {
    goBack () {
      this.$router.push({path: './inventoryManagement'})
    },
    selectionFn () {
      APIGAUGEGETEVALUATIONTYPELIST().then((res) => {
        this.selection = res.data
      }).catch((err) => {
        this.$message.error(err.msg)
      })
    },
    addMeasurementFn () {
      this.isAddMeasurement = true
    },
    noAddMeasurement (val) {
      this.isAddMeasurement = false
      console.log(val.val)
      this.title = val.val.title
      this.form.surveyls_survey_id = val.val.id
    },
    handleClose (val) {
      console.log(11)
      this.title = ''
      this.form.surveyls_survey_id = ''
    },
    submitFn () {
      APIGAUGEADDSCALEINFO(this.form).then((res) => {
        this.$message.success(res.msg)
        this.$router.push({path: './inventoryManagement'})
      }).catch((err) => {
        this.$message.error(err.msg)
      })
    }
  }
}
</script>
